﻿// ===================================
// The use and distribution terms for this software are covered by the Microsoft public license, 
// visit for more info : http://testcommander.codeplex.com 
// 
// You must not remove this copyright notice, or any other, from this software
// 
// Senthil Maruthaiappan  senips@gmail.com
// ===================================

using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using QAPro.Test.FitCommander;
using QAPro.Test.Interfaces;

namespace UnitTests.QAPro.Test.Library
{
    [TestClass]
    public class TestTestNode
    {
        private readonly TestServiceContext _testServiceContext = new TestServiceContext();

        [TestMethod]
        public void CreateASuite()
        {
            var suite = _testServiceContext.Services.Get<ISuite>("Test Suite");
            Assert.AreEqual("Test Suite", suite.Name);
            Assert.AreEqual("Test Suite", suite.PersistanceNode.Text);
            Assert.AreEqual(suite, suite.PersistanceNode.TestItem);
        }

        [TestMethod]
        public void CreateATestCase()
        {
            var suite = _testServiceContext.Services.Get<ISuite>("Test Suite");

            ITestCase test = suite.CreateTestCase("New Test Case");

            Assert.AreEqual("New Test Case", test.Name);
            Assert.AreEqual("New Test Case", test.PersistanceNode.Text);
            Assert.AreEqual(test, test.PersistanceNode.TestItem);
        }

        [TestMethod]
        public void CreateAFixtureTable()
        {
            var suite = _testServiceContext.Services.Get<ISuite>("Test Suite");
            ITestCase test = suite.CreateTestCase("New Test Case");
            IFixtureTable ftable = test.CreateFixtureTable("Sample Fixture Table-1");

            Assert.AreEqual("Sample Fixture Table-1", ftable.Name);
            Assert.AreEqual("Sample Fixture Table-1", ftable.PersistanceNode.Text);
            Assert.AreEqual(ftable, ftable.PersistanceNode.TestItem);
        }

        [TestMethod]
        public void TestEnumarable()
        {
            var suite = _testServiceContext.Services.Get<ISuite>("Test Suite");
            ITestCase test = suite.CreateTestCase("New Test Case");
            IFixtureTable ftable = test.CreateFixtureTable("Sample Fixture Table-1");
            suite.CreateSuite("suite2");
            Assert.AreEqual(2, suite.Count);

            var list = new List<object>();

            foreach (object o in suite)
            {
                list.Add(o);
            }

            Assert.AreEqual(2, list.Count);
        }


        [TestMethod]
        public void TestIndexAccess()
        {
            var suite = _testServiceContext.Services.Get<ISuite>("Test Suite");
            ITestCase test = suite.CreateTestCase("New Test Case");
            IFixtureTable ftable = test.CreateFixtureTable("Sample Fixture Table-1");
            suite.CreateSuite("suite2");
            Assert.AreEqual("New Test Case", suite[0].Name);
            Assert.AreEqual("suite2", suite[1].Name);
        }
    }
}